import time
import datetime


def get_today_date():
    """ 今天日期
    """
    today = datetime.date.today()
    return today


def get_yesterday_date():
    """ 昨天日期
    """
    today = get_today_date()
    yesterday = today - datetime.timedelta(days=1)
    return yesterday


def get_tomorrow_date():
    """ 明天日期
    """
    today = get_today_date()
    tomorrow = today + datetime.timedelta(days=1)
    return tomorrow


def get_yesterday_start_time():
    """ 获取昨天开始时间戳
    """
    yesterday = get_yesterday_date()
    yesterday_start_time = int(time.mktime(
        time.strptime(str(yesterday), '%Y-%m-%d')))
    return yesterday_start_time


def get_yesterday_end_time():
    """获取昨天结束时间戳
    """
    today = get_today_date()
    yesterday_end_time = int(time.mktime(
        time.strptime(str(today), '%Y-%m-%d'))) - 1
    return yesterday_end_time


def get_today_start_time():
    """今天开始时间戳
    """
    yesterday_end_time = get_yesterday_end_time()
    today_start_time = yesterday_end_time + 1
    return today_start_time


def get_today_end_time():
    """今天结束时间戳
    """
    tomorrow = get_tomorrow_date()
    today_end_time = int(time.mktime(
        time.strptime(str(tomorrow), '%Y-%m-%d'))) - 1
    return today_end_time


def get_tomorrow_start_time():
    """明天开始时间戳
    """
    tomorrow = get_tomorrow_date()
    tomorrow_start_time = int(time.mktime(
        time.strptime(str(tomorrow), '%Y-%m-%d')))
    return tomorrow_start_time


def get_tomorrow_end_time():
    """明天结束时间戳
    """
    today = get_today_date()
    acquire = today + datetime.timedelta(days=2)
    tomorrow_end_time = int(time.mktime(
        time.strptime(str(acquire), '%Y-%m-%d'))) - 1
    return tomorrow_end_time


def get_start_time_by_timestamp(ts):
    """根据时间戳获取当天的开始时间戳
    """
    timeArray = time.localtime(ts)
    date = time.strftime("%Y-%m-%d", timeArray)
    tss1 = date + " 00:00:00"
    timeArray = time.strptime(tss1, "%Y-%m-%d %H:%M:%S")
    ts_return = int(time.mktime(timeArray))
    return ts_return


def turn_ts_to_date(ts):
    """将时间戳转换为日期格式
    """
    timeArray = time.localtime(ts)
    date = time.strftime("%Y-%m-%d", timeArray)
    tss1 = date + " 00:00:00"
    return tss1


def turn_date_to_ts(date):
    """将日期转换为时间戳格式
    """
    # 转为时间数组
    timeArray = time.strptime(date, "%Y-%m-%d")
    timeStamp = int(time.mktime(timeArray))
    return timeStamp